package com.wondertek.poms.core.utils;

import java.io.File;
import java.io.FileFilter;

/**
 * @author gaozhengxing gaozhenghang@wondertek.com.cn
 * @date 2021/1/4 13:48
 * @description TODO
 */
public class PagingFileFilter implements FileFilter {
    private String fname;

    public PagingFileFilter(String fname) {
        this.fname = fname;
    }

    @Override
    public boolean accept(File fileName) {
        if (fileName != null && this.fname != null) {
            String[] names;
            if (this.fname.indexOf("*All.*") > 0) {
                names = this.fname.split("\\*All.*");
                if (names.length > 0) {
                    if (fileName.getName().startsWith(names[0] + ".")) {
                        return true;
                    }

                    if (fileName.getName().startsWith(names[0] + "_")) {
                        return true;
                    }
                }
            } else if (this.fname.indexOf("*All.") > 0) {
                names = this.fname.split("\\*All.");
                if (names.length > 1) {
                    if (fileName.getName().startsWith(names[0] + ".")) {
                        return true;
                    }

                    if (fileName.getName().startsWith(names[0] + "_")) {
                        return true;
                    }
                }
            } else if (this.fname.indexOf(".*") > 0) {
                names = this.fname.split("[.*]");
                if (fileName.getName().startsWith(names[0] + ".")) {
                    return true;
                }
            } else if (this.fname.indexOf("*") > 0) {
            }

            return false;
        } else {
            return false;
        }
    }
}
